<template>
    <view>
        <cu-custom bgColor="bg-white" :isBack="true">
            <block slot="content">账户安全</block>
        </cu-custom>
        <view class="padding">
            <view class="item crow padding-lg bg-white radius-xl margin-bottom"
            @tap="$utils.$page.open('/pages/user/account/mobile')">
                <view class="left text-left">绑定手机</view>
                <view class="right text-right">{{ USERINFO.mobile }}</view>
                <text class="cuIcon-right"></text>
            </view>
            <view class="item crow padding-lg bg-white radius-xl margin-bottom"
            @tap="$utils.$page.open('/pages/user/account/password')">
                <view class="left text-left">修改密码</view>
                <view class="right text-right"></view>
                <text class="cuIcon-right"></text>
            </view>
            <view class="item crow padding-lg bg-white radius-xl margin-bottom" v-if="WEBCONFIG.wx_state"
            @tap="bindWechat">
                <view class="left text-left">绑定微信</view>
                <!-- #ifdef H5 -->
                <view class="right text-right" v-if="USERINFO.openid">{{ USERINFO.wechat_nickname }}</view>
                <!-- #endif -->
                <!-- #ifdef MP-WEIXIN -->
                <view class="right text-right" v-if="USERINFO.mp_openid">{{ USERINFO.wechat_nickname }}</view>
                <!-- #endif -->
                <view class="right text-right" v-else>未绑定</view>
                <text class="cuIcon-right"></text>
            </view>
            <view class="item crow padding-lg bg-white radius-xl margin-bottom"
            @tap="$utils.$page.open('/pages/user/finance/index')">
                <view class="left text-left">收款账户</view>
                <view class="right text-right"></view>
                <text class="cuIcon-right"></text>
            </view>
        </view>
    </view>
</template>

<script>
import { mapState } from 'vuex'
export default {
	computed: {
		...mapState({
			USERINFO: state => state.USER.USERINFO,
			WEBCONFIG: state => state.WEBCONFIG,
		})
	},
    data() {
        return {
            pageLoading: false,

        };
    },
    onLoad() {
    },
    methods: {
        bindWechat(){
            // #ifdef H5
            if(!this.USERINFO.openid){
                this.$utils.$api.User.bindWechat({
                    redirect:'bind'
                })
                .then((res) => {
                    globalThis.location.href = res.data;
                }).catch((err) => {
                    this.$utils.$message.error(err.msg);
                });
            }else{
                uni.showModal({
                    title: '提示',
                    content: '是否解除绑定',
                    success: (res) => {
                        if (res.confirm) {
                            this.$utils.$api.User.unBindWechat().then(() => {
				                this.$utils.$api.User.userinfo(this, true);
                                this.$utils.$message.success('解绑成功');
                            }).catch((err) => {
                                this.$utils.$message.error(err.msg);
                            })
                        }
                    }
                })
            }
            // #endif
        }
    }
}
</script>

<style lang="less" scoped>
.item {
    width: 100%;

    .left {
        width: 25%;
    }

    .right {
        flex: 1;
    }
}
</style>
